package com.spring.utils.api_v4.config;

import com.spring.utils.api_v4.pojo.DeptInfo;
import com.spring.utils.api_v4.pojo.salary.DeptWage;
import com.spring.utils.api_v4.pojo.salary.EmployeeWage;
import com.spring.utils.api_v4.service.ISalaryService;
import com.spring.utils.api_v4.service.ISystemService;
import com.spring.utils.api_v4.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 系统启动后执行检查
 */
@Component
public class ApplicationRunnerImpl implements ApplicationRunner {
    @Autowired private ISystemService systemService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        initWages();
    }

    /**
     * 初始化工资信息
     */
    private void initWages() {
        // 初始化部门工资信息
//        systemService.getDeptsAll().forEach(dept -> {
//            DeptWage dw = systemService.getDeptWage(dept);
//            if(dw == null) {
//                DeptWage ndw = new DeptWage();
//                ndw.setId(dept.getId());
//                ndw.setName(dept.getName());
//                systemService.saveDeptWage(ndw);
//            }
//            dept.setStaff(systemService.getStaffOfDept(dept));
//            // 初始化员工工资信息
//            dept.getStaff().forEach(user -> {
//                EmployeeWage ew = systemService.getEmployeeWage(user);
//                if(ew == null) {
//                    EmployeeWage enw = new EmployeeWage();
//                    enw.setUserInfo(user);
//                    systemService.saveEmployeeWage(enw);
//                }
//            });
//        });
    }
}
